# Contributor: mio <miyopan@e.email>
# Maintainer: mio <miyopan@e.email>
pkgname=drawpile
pkgver=2.1.20
pkgrel=3
pkgdesc="Collaborative drawing program"
url="https://drawpile.net/"
license="GPL-3.0-or-later"
arch="all !armhf" # Missing karchive-dev kdnssd-dev on armhf
pkgusers=drawpile
pkggroups=drawpile
makedepends="
	cmake
	extra-cmake-modules
	giflib-dev
	karchive5-dev
	kdnssd5-dev
	libmicrohttpd-dev
	libsodium-dev
	libvpx-dev
	miniupnpc-dev
	qt5-qtmultimedia-dev
	qt5-qtsvg-dev
	qt5-qttools-dev
	qt5-qtx11extras-dev
	samurai
	"
subpackages="
	$pkgname-doc
	$pkgname-base
	$pkgname-client
	$pkgname-server
	$pkgname-server-openrc
	"
source="drawpile-$pkgver.tar.gz::https://github.com/drawpile/Drawpile/archive/$pkgver.tar.gz
	drawpile.initd
	drawpile-server.pre-install
	"
builddir="$srcdir"/Drawpile-"$pkgver"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DTESTS="$(want_check && echo ON || echo OFF)" \
		-DTOOLS=ON
	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	# drawpile is a meta-package
	depends="
		$pkgname-base=$pkgver-r$pkgrel
		$pkgname-client=$pkgver-r$pkgrel
		$pkgname-server=$pkgver-r$pkgrel
		"
	DESTDIR="$pkgdir" cmake --install build

	install -Dm755 "$srcdir"/drawpile.initd "$pkgdir"/etc/init.d/drawpile
}

base() {
	pkgdesc="Common files for Drawpile"
	amove usr/share
}

client() {
	pkgdesc="$pkgdesc (Drawpile client)"
	depends="$pkgname-base=$pkgver-r$pkgrel"
	amove usr/bin/drawpile-$pkgver
	amove usr/bin/drawpile
	# dprectool: convert between Drawpile session formats .dprec and .dptxt
	# drawpile-cmd: render recordings
	amove usr/bin/dprectool
	amove usr/bin/drawpile-cmd
}

server() {
	pkgdesc="$pkgdesc (Drawpile server)"
	depends="
		$pkgname-base=$pkgver-r$pkgrel
		qt5-qtbase-sqlite
		"

	amove usr/bin/drawpile-srv

	install -d -o drawpile -g drawpile "$subpkgdir"/etc/drawpile/templates
	install -d -o drawpile -g drawpile -m 750 "$subpkgdir"/var/lib/drawpile
}

sha512sums="
59a9946af8e1e877e0e3dc1fc0c4ab2c6b77de4c7ebba78d82fc67e95dfb5d4fc25d68b461e20283eb40bc49f3412838eeffda335c62d3c98492b505e8b24937  drawpile-2.1.20.tar.gz
5a2e6d1e677a74a43838cce26bd6b6f6bceb858f3622912476665ad3f6cef3171aa0c5b56ca9343c5b7ec81c850ce251a177d77490854e7ef39796c4c7d53535  drawpile.initd
712df7a0bac0d4ad25f4254f0caf09b4d496b64d1d0a8bbbdd28e3b6c10ac6305dab58ac48adc8b88d0b7c8898ce28613ae2e8951ba76ad2ef5da35b3d943a94  drawpile-server.pre-install
"
